#include<stdio.h>
struct ExamData
{
    long long Code;
    int PreSeat;
    int Seat;
};

int main()
{
    int N;
    scanf("%d", &N);
    struct ExamData imf[N];

    for(int i = 0; i < N; i ++)
    {
        scanf("%lld %d %d", &imf[i].Code, &imf[i].PreSeat, &imf[i].Seat);
    }

    int M;
    scanf("%d", &M);

    for(int i = 0; i < M; i ++)
    {
        int dst;
        scanf("%d", &dst);
        for(int j = 0 ; j < N; j ++)
        {
            if(imf[j].PreSeat == dst)
            {
                printf("%lld %d\n", imf[j].Code, imf[j].Seat);
            }
        }
    }

    return 0;
}
